<!DOCTYPE html>
<html>
<title>倒计时关闭网页</title>
<head>
    <script>
        var s = 1, t;
        function times(){
            s--;
            document.form.time.value = s;
            t = setTimeout('times', 1000);
            if ( s <= 0 ){
                s = 60;
                clearTimeout(t);
            }
            alert(s);
        }
        times();
    </script>
</head>
<body>
<span id="time">5秒钟后自动关闭</span><br>
<a href="javascript:clearTimeout(timer)">留在本页</a>
</body>
</html>